<?php
namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;


class LoginFilter implements FilterInterface
{
    // 前置过滤器
    public function before(RequestInterface $request, $arguments = null)
    {
        // 监测是否登录
        if (!session()->get('user'))
        {
            return redirect('login');
        }
    }

    //--------------------------------------------------------------------
    // 后置过滤器(不能省略)
    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // Do something here
    }
}